<template>
  <div>
    <el-table
      :data="studentList"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="学生姓名">
      </el-table-column>
      <el-table-column
        prop="pwd"
        label="密码">
      </el-table-column>

      <el-table-column
        prop="stuNo"
        label="学号">
      </el-table-column>

      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button @click="deleteById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <router-view/>
  </div>
</template>

<script>
    export default {
        name: "studentList",
      data(){
          return {
            studentList:[],
            cid:""
          }
      },
      created(){
        this.selectAll();
        this.cid=this.$route.query.cid;
        this.selectAll();
      },
      methods: {
        deleteById(id){
          this.$confirm("是否确认删除","删除提示").then(()=>{
            this.axios.delete("/student/deleteById/"+id).then((resp)=>{
              this.$message.success("删除成功！");
              this.selectAll();
            });
          });
        },
        selectAll(){
          let url="";
          if(this.cid!=""){
            url="/student/selectByCid?cid="+this.cid;
          }else{
            url="/student/selectAll"
          }
          this.axios.get(url).then((resp)=>{
            this.studentList=resp.data;
          });
        }
      }
    }
</script>

<style scoped>

</style>
